import { DataTypes, Model } from 'sequelize'
import { sequelize } from '../../connect'
import { findAllValues, findOneRandomValue, findOneValue } from '../../public'

type ModelProps = {
  id: number
  uid: number // 用户uid
  skill_name: string // 技能名
  skill_level: number // 技能等级
  skill_use: number //技能代码
}

class user_skill extends Model<ModelProps> {
  public static findAllValues = findAllValues
  public static findOneValue = findOneValue
  public static findOneRandomValue = findOneRandomValue
  item_name: any
}

user_skill.init(
  {
    id: {
      type: DataTypes.BIGINT,
      primaryKey: true,
      allowNull: false,
      autoIncrement: true,
      comment: '表id'
    },
    uid: {
      type: DataTypes.STRING(20),
      allowNull: false,
      comment: '用户uid'
    },
    skill_name: {
      type: DataTypes.STRING(50),
      allowNull: false,
      comment: '技能名'
    },
    skill_level: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 1,
      comment: '技能等级'
    },
    skill_use: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: '技能代码'
    }
  },
  {
    sequelize,
    tableName: 'user_skill',
    freezeTableName: true,
    createdAt: false,
    updatedAt: false,
    indexes: [
      {
        unique: false,
        fields: ['id']
      }
    ]
  }
)

export { user_skill }
